import { defineStore } from 'pinia'

import $axios from '../tools/axios'
// import {useRouter} from 'vue-router'

// const router = useRouter();

const basepath = '/user'
export const useMyinfoStore = defineStore('myinfo', {
  state: () => {
    return {
       formData:''
    }
  },
  actions: {
    async queryMyInfo() {
      const path = basepath + '/myinfo'

      const { data: res } = await $axios.post(path,JSON.parse(sessionStorage.getItem('user')))

      if (res.code === 200) {
        
        console.log(res.data);
        this.formData = res.data
        if( this.formData.idtype == 1 )
        {
            this.formData.idtype = '中国居民身份证'
        }
        if( this.formData.favortype == 1 )
        {
            this.formData.favortype = '成人'
        }
        if( this.formData.mobiletype == 1 )
        {
            this.formData.mobiletype = '+86 中国'
        }
        this.formData.amount = this.formData.amount.toFixed(2)
      
      } 
    }
  }
})
